/* $Id:action.h $ */
/*
   Copyright (C) 2007 by Jurjen Stellingwerff <jurjen@stwerff.xs4all.nl>
   Part of the Moros Project http://moros.sourceforge.net/

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License version 3.
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY.

   See the COPYING file for more details.
*/

#ifndef __ACTION_H
#define __ACTION_H

#include <string>
#include <map>
#include <list>
using namespace std;

#include "action_skill.h"
#include "action_bonus.h"

#define loopActionSkills(r,v) loopMap((r)->listSkills(),v,class action_skill)
#define loopActionBonus(r,v) loopMapi((r)->listBonus(),v,class action_bonus)

class action {
    string name;
    string description;
    int type;
    class skill *deity;
    int time;
    int time_base;
    int endurance;
    int range;
    int aiming;
    int energy;
    map<string,class action_skill> skills;
    map<int,class action_bonus> bonus;
    int maxBonus;
public:
    action();

    // Field : name
    const string getName() const;
    void setName(const string v);

    // Field : description
    const string getDescription() const;
    void setDescription(const string v);

    // Field : type
    enum type_enum{type_free,type_tools,type_transport,type_building};
    const int getType() const;
    const string showType() const;
    void setType(const int v);
    void setType(const string v);

    // Field : deity
    class skill& getDeity() const;
    void setDeity(class skill &v);

    // Field : time
    const int getTime() const;
    void setTime(const int v);

    // Field : time_base
    enum time_base_enum{time_base_second,time_base_minute,time_base_hour,time_base_day,time_base_week,time_base_month,time_base_year};
    const int getTime_base() const;
    const string showTime_base() const;
    void setTime_base(const int v);
    void setTime_base(const string v);

    // Field : endurance
    const int getEndurance() const;
    void setEndurance(const int v);

    // Field : range
    const int getRange() const;
    void setRange(const int v);

    // Field : aiming
    const int getAiming() const;
    void setAiming(const int v);

    // Field : energy
    const int getEnergy() const;
    void setEnergy(const int v);

    // Field : skills
    class action_skill& getSkills(const string v);
    map<string,class action_skill>& listSkills();
    void setSkills(class action_skill &v);
    void delSkills(const string v);
    const bool isSkills(const string v) const;

    // Field : bonus
    class action_bonus& getBonus(const int v);
    map<int,class action_bonus>& listBonus();
    void setBonus(class action_bonus &v);
    void delBonus(const int v);
    const bool isBonus(const int v) const;

    void save(class channel &ch);
    void load(class channel &ch);
    void xml(ofstream &f, int l=0, int r=0);
};

// Repository

#define loopActions(v) loopMap(action_repo.listAction(),v,class action)

class actionRepository {
    map<string,action> actions;
public:
    class action& getAction(const string v);
    void setAction(class action& v);
    map<string,class action>& listAction();
    void delAction(const string v);
    const bool isAction(const string v) const;
    multimap<string, sigc::signal<void, class action& > > relations;
    bool load(class channel &ch);
    void save(class channel &ch);
};

extern actionRepository action_repo;

#endif // __ACTION_H
